<%--
  Created by IntelliJ IDEA.
  User: Ly
  Date: 2017/9/19
  Time: 19:10
  Content: 获取所有计划中的任务列表   所有正在运行的job
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fnx" uri="http://java.sun.com/jsp/jstl/functionsx" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="f" uri="http://www.sctv.com/tags/form" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<head>
    <jsp:include page="/WEB-INF/views/head.jsp"/>
    <script>
        <%--$(function () {--%>
        <%--$("#sortHead").headSort();--%>

        <%--<shiro:hasPermission name="ext:push:view">--%>
        <%--$("#pagedTable tbody tr").dblclick(function (eventObj) {--%>
        <%--var nodeName = eventObj.target.nodeName.toLowerCase();--%>
        <%--if (nodeName != "input" && nodeName != "select" && nodeName != "textarea") {--%>
        <%--location.href = $("#view_opt_" + $(this).attr("beanid")).attr('href');--%>
        <%--}--%>
        <%--});--%>
        <%--</shiro:hasPermission>--%>
        <%--});--%>

        function confirmDelete() {
            return confirm("<s:message code='confirmDelete'/>");
        }

        function optSingle(opt) {
            if (Cms.checkeds("ids") == 0) {
                alert("<s:message code='pleaseSelectRecord'/>");
                return false;
            }
            if (Cms.checkeds("ids") > 1) {
                alert("<s:message code='pleaseSelectOne'/>");
                return false;
            }
            var id = $("input[name='ids']:checkbox:checked").val();
            location.href = $(opt + id).attr("href");
        }

        function optMulti(form, action, msg) {
            if (Cms.checkeds("ids") == 0) {
                alert("<s:message code='pleaseSelectRecord'/>");
                return false;
            }
            if (msg && !confirm(msg)) {
                return false;
            }
            form.action = action;
            form.submit();
            return true;
        }

        function optDelete(form) {
            if (Cms.checkeds("ids") == 0) {
                alert("<s:message code='pleaseSelectRecord'/>");
                return false;
            }
            if (!confirmDelete()) {
                return false;
            }
            form.action = 'delete.do';
            form.submit();
            return true;
        }
    </script>
</head>
<body class="skin-blue content-body">
<jsp:include page="/WEB-INF/views/commons/show_message.jsp"/>
<div class="content-header">
    <h1>[未执行]定时任务管理 - <s:message code="list"/>
        <small>(<s:message code="totalElements" arguments="${pagedList.totalElements}"/>)</small>
    </h1>
</div>
<div class="content">
    <div class="box box-primary">
        <div class="box-body table-responsive">
            <form action="list.do" method="get" class="form-inline ls-search">
                <div class="form-group">
                    <label for="search_LIKE_jobName">名称</label>
                    <input class="form-control input-sm" type="text" id="search_LIKE_jobName" name="search_LIKE_jobName"
                           value="${search_LIKE_jobName[0]}"/>
                </div>
                <div class="form-group">
                    <label for="search_LIKE_jobGroup">分组</label>
                    <input class="form-control input-sm" type="text" id="search_LIKE_jobGroup"
                           name="search_LIKE_jobGroup"
                           value="${search_LIKE_jobGroup[0]}"/>
                </div>
                <div class="form-group">
                    <label for="search_EQ_jobStatus">状态</label>
                    <select class="form-control" name="search_EQ_jobStatus" id="search_EQ_jobStatus">
                        <f:option value="">全部</f:option>
                        <f:option value="0">关闭</f:option>
                        <f:option value="1">开启</f:option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="search_EQ_isRestore">任务状态</label>
                    <select class="form-control" name="search_EQ_isRestore" id="search_EQ_isRestore">
                        <f:option value="">全部</f:option>
                        <f:option value="0">正常</f:option>
                        <f:option value="1">恢复</f:option>
                        <f:option value="2">暂停</f:option>
                    </select>
                </div>

                <button class="btn btn-default btn-sm" type="submit"><s:message code="search"/></button>
            </form>
            <form method="post">
                <div class="btn-toolbar ls-btn-bar">
                    <div class="btn-group">

                        <shiro:hasPermission name="ext:task:create">
                            <button class="btn btn-default" type="button"  onclick="location.href='create.do';">
                                <s:message code="create"/></button>
                        </shiro:hasPermission>

                        <shiro:hasPermission name="ext:task:delete">
                            <button class="btn btn-default" type="button" onclick="return optDelete(this.form);">
                                <s:message code="delete"/></button>
                        </shiro:hasPermission>

                        <shiro:hasPermission name="ext:task:changeJobStatus">
                            <button class="btn btn-default" type="button"
                                    onclick="return optMulti(this.form,'changeJobStatus.do?cmd=start');">
                                开启定时任务
                            </button>
                        </shiro:hasPermission>
                    </div>
                </div>

                <table id="pagedTable" class="table table-condensed table-bordered table-hover ls-tb">
                    <thead id="sortHead" pagesort="<c:out value='${page_sort[0]}' />" pagedir="${page_sort_dir[0]}"
                           pageurl="list.do?page_sort={0}&page_sort_dir={1}&${searchstringnosort}">
                    <tr>
                        <th width="25"><input type="checkbox" onclick="Cms.check('ids',this.checked);"/></th>
                        <th width="120"><s:message code="pushMsg.operate"/></th>
                        <th width="30" class="ls-th-sort"><span class="ls-sort" pagesort="id">ID</span></th>
                        <th class="ls-th-sort"><span class="ls-sort" pagesort="jobName">名称</span></th>
                        <th class="ls-th-sort"><span class="ls-sort" pagesort="jobGroup">分组</span></th>
                        <th class="ls-th-sort"><span class="ls-sort" pagesort="jobStatus">启动状态</span></th>
                        <th class="ls-th-sort"><span class="ls-sort" pagesort="isRestore">任务状态</span></th>
                        <th class="ls-th-sort"><span class="ls-sort" pagesort="cronExpression">表达式</span></th>
                        <th class="ls-th-sort"><span class="ls-sort" pagesort="createTime">时间</span></th>
                        <th class="ls-th-sort"><span class="ls-sort" pagesort="id">操作</span></th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach var="bean" varStatus="status" items="${pagedList.content}">
                        <tr beanid="${bean.id}">
                            <td align="center"><input type="checkbox" name="ids" value="${bean.id}"/></td>
                            <td align="center"><c:out value="${bean.user.username}"/></td>
                            <td align="center"><c:out value="${bean.id}"/></td>
                            <td align="center"><c:out value="${bean.jobName}"/></td>
                            <td align="center"><c:out value="${bean.jobGroup}"/></td>
                            <td align="center"><s:message code="task.jobStatus.${bean.jobStatus}"/></td>
                            <td align="center"><s:message code="task.isRestore.${bean.isRestore}"/></td>
                            <td align="center"><c:out value="${bean.cronExpression}"/></td>
                            <td align="center">
                                原始: <fmt:formatDate value="${bean.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></br>
                                更新: <fmt:formatDate value="${bean.updateTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                            </td>
                            <td align="center">

                                <shiro:hasPermission name="ext:task:changeJobStatus">
                                    <a href="changeJobStatus.do?cmd=start&ids=${bean.id}" class="ls-opt">开启</a>
                                </shiro:hasPermission>

                                <shiro:hasPermission name="ext:task:edit">
                                    <a href="edit.do?id=${bean.id}&position=${pagedList.number*pagedList.size+status.index}" class="ls-opt">修改</a>
                                </shiro:hasPermission>

                                <shiro:hasPermission name="ext:task:delete">
                                    <a href="delete.do?ids=${bean.id}" class="ls-opt">删除</a>
                                </shiro:hasPermission>

                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <c:if test="${fn:length(pagedList.content) le 0}">
                    <div class="ls-norecord"><s:message code="recordNotFound"/></div>
                </c:if>
            </form>
            <form action="list.do" method="GET" class="ls-page">
                <tags:search_params excludePage="true"/>
                <tags:pagination  pagedList="${pagedList}"/>
            </form>
        </div>
    </div>
</div>
</body>
</html>
